/*
 * ServerConfig.cpp
 *
 */

#include "ServerConfig.h"
#include <exception>


ServerConfig::ServerConfig(std::string nomArchXML):
Configuraciones(nomArchXML) {}


ServerConfig::~ServerConfig(){}

Port ServerConfig::getWebPort() const {
	return static_cast<Port>(this->nroPuerto);
}

Port ServerConfig::getCtrlPort() const {
	return static_cast<Port>(this->nroPuertoCtrl);
}

unsigned short int ServerConfig::getMaxSimulConn() const {
	return this->maxConexionesSimultaneas;
}

unsigned short int ServerConfig::getMaxClientConn() const {
	return this->maxConexionesCliente;
}

const std::string& ServerConfig::getRootPath() const{
	return this->baseDir;
}

std::string ServerConfig::getStaticType(const std::string& extension) const {
	std::map<std::string, std::string>::const_iterator it;
	it = this->mapTiposEstaticos.find(extension);

	if (it == this->mapTiposEstaticos.end())
		throw std::string("Unknown static type");

	return it->second;
}


std::string ServerConfig::getDynamicType(const std::string& extension) const {
	std::map<std::string, std::string>::const_iterator it;
	it = this->mapTiposDinamicos.find(extension);

	if (it == this->mapTiposDinamicos.end())
		throw std::string("Unknown dinamic type");

	return it->second;
}


std::string ServerConfig::getErrorHandler(const std::string& code) const {
	std::map<std::string, std::string>::const_iterator it;
	it = this->mapPaginasErrores.find(code);

	if (it == this->mapPaginasErrores.end())
		throw std::string("Unknown error code");

	return it->second;
}


bool ServerConfig::getProtectionFlag() const{
	return this->autenticacionBasica;
}

bool ServerConfig::isUserAuthorized(const std::string& user,
		const std::string& pass) const {
	bool result = false;
	std::map<std::string, std::string>::const_iterator it;
	it = mapUsuarios.find(user);
	if (it != mapUsuarios.end() && it->second == pass)
		result = true;
	return result;
}


unsigned short int ServerConfig::getTimeout() const{
	return this->timeout;
}
